<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Message消息提示</title>
    <style>
        /* 基础样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 40px 20px;
        }

        .container {
            max-width: 800px;
            width: 100%;
            text-align: center;
        }

        h1 {
            color: white;
            margin-bottom: 30px;
            font-size: 2.5rem;
            text-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .controls {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            margin-bottom: 30px;
        }

        .control-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #333;
        }

        input, select, textarea {
            width: 100%;
            padding: 12px;
            border: 2px solid #e1e5e9;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: #667eea;
        }

        textarea {
            min-height: 80px;
            resize: vertical;
        }

        .button-group {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            justify-content: center;
            margin-top: 20px;
        }

        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
        }

        .btn:active {
            transform: translateY(0);
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .btn-success {
            background: linear-gradient(135deg, #96fbc4 0%, #45c6ff 100%);
            color: white;
        }

        .btn-warning {
            background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
            color: white;
        }

        .btn-danger {
            background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
            color: white;
        }

        /* 消息容器 */
        .message-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
            width: 380px;
        }

        /* 单个消息样式 */
        .message {
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
            margin-bottom: 15px;
            overflow: hidden;
            transform: translateX(120%);
            opacity: 0;
            transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        }

        .message.show {
            transform: translateX(0);
            opacity: 1;
        }

        .message.hide {
            transform: translateX(120%);
            opacity: 0;
            transition: all 0.3s ease-in-out;
        }

        .message-content {
            display: flex;
            align-items: flex-start;
            padding: 20px;
        }

        .message-icon {
            font-size: 24px;
            margin-right: 15px;
            width: 24px;
            height: 24px;
        }

        .message-body {
            flex: 1;
        }

        .message-title {
            font-weight: 600;
            margin-bottom: 5px;
            font-size: 18px;
        }

        .message-text {
            color: #666;
            line-height: 1.5;
        }

        .message-close {
            background: none;
            border: none;
            font-size: 20px;
            cursor: pointer;
            color: #999;
            padding: 0;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 15px;
            transition: color 0.2s;
        }

        .message-close:hover {
            color: #333;
        }

        /* 不同类型消息的颜色 */
        .message-info .message-icon {
            color: #667eea;
        }

        .message-success .message-icon {
            color: #4CAF50;
        }

        .message-warning .message-icon {
            color: #FF9800;
        }

        .message-error .message-icon {
            color: #F44336;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .message-container {
                width: calc(100% - 40px);
                right: 20px;
                left: 20px;
            }

            h1 {
                font-size: 2rem;
            }

            .controls {
                padding: 20px;
            }
        }

        @media (max-width: 480px) {
            .button-group {
                flex-direction: column;
            }

            .btn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <h1>Message消息提示组件</h1>

    <div class="controls">
        <div class="control-group">
            <label for="messageTitle">消息标题</label>
            <input type="text" id="messageTitle" placeholder="请输入消息标题" value="操作成功">
        </div>

        <div class="control-group">
            <label for="messageContent">消息内容</label>
            <textarea id="messageContent" placeholder="请输入消息内容">这是一条成功消息的示例内容</textarea>
        </div>

        <div class="control-group">
            <label for="messageType">消息类型</label>
            <select id="messageType">
                <option value="info">信息 (Info)</option>
                <option value="success" selected>成功 (Success)</option>
                <option value="warning">警告 (Warning)</option>
                <option value="error">错误 (Error)</option>
            </select>
        </div>

        <div class="control-group">
            <label for="autoClose">自动关闭时间 (秒)</label>
            <input type="number" id="autoClose" min="1" max="30" value="5">
        </div>

        <div class="button-group">
            <button class="btn btn-primary" onclick="showMessage()">显示消息</button>
            <button class="btn btn-success" onclick="showSuccessMessage()">成功消息</button>
            <button class="btn btn-warning" onclick="showWarningMessage()">警告消息</button>
            <button class="btn btn-danger" onclick="showErrorMessage()">错误消息</button>
        </div>
    </div>
</div>

<!-- 消息容器 -->
<div class="message-container" id="messageContainer"></div>

<script>
    // 消息计数器，用于生成唯一ID
    let messageCounter = 0;

    /**
     * 显示消息的主函数
     * @param {string} title - 消息标题
     * @param {string} content - 消息内容
     * @param {string} type - 消息类型 (info, success, warning, error)
     * @param {number} duration - 自动关闭时间(毫秒)
     */
    function showMessage(title, content, type, duration) {
        // 如果没有传参，则从表单获取
        const msgTitle = title || document.getElementById('messageTitle').value || '提示';
        const msgContent = content || document.getElementById('messageContent').value || '这是一条消息';
        const msgType = type || document.getElementById('messageType').value || 'info';
        const msgDuration = duration || (document.getElementById('autoClose').value * 1000) || 5000;

        // 生成唯一ID
        const messageId = 'message-' + (++messageCounter);

        // 创建消息元素
        const messageElement = document.createElement('div');
        messageElement.className = `message message-${msgType}`;
        messageElement.id = messageId;

        // 根据消息类型设置图标
        let iconHtml = '';
        switch(msgType) {
            case 'success':
                iconHtml = '✓';
                break;
            case 'warning':
                iconHtml = '⚠';
                break;
            case 'error':
                iconHtml = '✕';
                break;
            default:
                iconHtml = 'ℹ';
        }

        // 设置消息内容
        messageElement.innerHTML = `
                <div class="message-content">
                    <div class="message-icon">${iconHtml}</div>
                    <div class="message-body">
                        <div class="message-title">${msgTitle}</div>
                        <div class="message-text">${msgContent}</div>
                    </div>
                    <button class="message-close" onclick="closeMessage('${messageId}')">×</button>
                </div>
            `;

        // 添加到消息容器
        const container = document.getElementById('messageContainer');
        container.appendChild(messageElement);

        // 触发显示动画
        setTimeout(() => {
            messageElement.classList.add('show');
        }, 10);

        // 自动关闭定时器
        if (msgDuration > 0) {
            setTimeout(() => {
                closeMessage(messageId);
            }, msgDuration);
        }
    }

    /**
     * 关闭指定消息
     * @param {string} id - 消息元素ID
     */
    function closeMessage(id) {
        const messageElement = document.getElementById(id);
        if (messageElement) {
            // 添加隐藏动画类
            messageElement.classList.add('hide');

            // 动画结束后移除元素
            setTimeout(() => {
                if (messageElement.parentNode) {
                    messageElement.parentNode.removeChild(messageElement);
                }
            }, 300);
        }
    }

    /**
     * 显示成功消息的快捷函数
     */
    function showSuccessMessage() {
        showMessage('操作成功', '您的操作已成功完成！', 'success', 3000);
    }

    /**
     * 显示警告消息的快捷函数
     */
    function showWarningMessage() {
        showMessage('警告', '请注意，这是一条警告信息。', 'warning', 4000);
    }

    /**
     * 显示错误消息的快捷函数
     */
    function showErrorMessage() {
        showMessage('操作失败', '抱歉，操作过程中出现了错误。', 'error', 5000);
    }

    // 页面加载完成后初始化
    document.addEventListener('DOMContentLoaded', function() {
        // 可以在这里添加初始化代码
    });
</script>
</body>
</html>